package com.example.administrator.rxjavarxandroid_retrofit.base;

import android.app.Activity;
import android.os.Bundle;

import com.example.administrator.rxjavarxandroid_retrofit.App;
import com.example.administrator.rxjavarxandroid_retrofit.http.api.CommonApi;
import com.example.administrator.rxjavarxandroid_retrofit.reject.component.ActivityComponent;
import com.example.administrator.rxjavarxandroid_retrofit.reject.component.AppComponent;
import com.example.administrator.rxjavarxandroid_retrofit.reject.moudle.ActivityModule;

import javax.inject.Inject;

import butterknife.ButterKnife;

/**
 * Created by chenboge on 2016/12/18.
 */
public abstract class BaseActivity<T extends IPresenter> extends Activity implements IView{

    @Inject
    protected T mPresenter;

    @Inject
    public CommonApi mApi;

    protected Activity mContext;

    public ActivityComponent mComponent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayoutResId());
        ButterKnife.bind(this);
        this.mContext = this;
        setupActivityComponent(App.getAppComponent(), new ActivityModule(this));
        if (mPresenter != null)
            mPresenter.attachView(this);
        initEventAndData();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
        if (mPresenter != null) mPresenter.detachView();
    }

    protected abstract int setLayoutResId();

    protected abstract void setupActivityComponent(AppComponent appComponent, ActivityModule activityModule);

    protected abstract void initEventAndData();


}
